import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* 路由器模块 */
import sysTemRouter from './modules/system' // 系统管理
import enterpriseRouter from './modules/enterprise' // 企业设定
import superviseBaseInfoRouter from './modules/superviseBaseInfo' // 基本信息
import systemConfig from './modules/systemConfig' // 系统配置
import resourceManage from './modules/resourceManage' // 资源管理
import newProject from './modules/newProject' // 新项目管理
import projectControl from './modules/projectControl' // 项目管控
import PersonalOfficeRouter from './modules/PersonalOffice' // 个人办公
import statisticalAnalysis from './modules/statisticalAnalysis' // 统计分析
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true, // 当设置 true 的时候该路由不会在侧边栏出现 如401，login等页面
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  // 门户页
  {
    path: '/main',
    component: () => import('@/views/home/main'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/index', // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
    children: [
      {
        path: 'index',
        name: '监管首页',
        meta: {
          footerHidden: true // 隐藏底部栏
        },
        component: () => import('@/views/home/superviseIndex/index')
      },
      {
        path: 'secondPage',
        component: () => import('@/views/home/secondPage'),
        name: '监管二级页面',
        meta: {
          footerHidden: true, // 隐藏底部栏
          title: 'secondPage',
          icon: 'dashboard',
          affix: true // 若果设置为true，它则会固定在tags-view中(默认 false)
        },
        activeMenu: 'home'
      },
      {
        path: 'enterpriseIndex',
        component: () => import('@/views/home/enterpriseIndex'),
        name: '企业首页',
        meta: {
          footerHidden: true, // 隐藏底部栏
          title: 'enterpriseIndex',
          icon: 'dashboard',
          affix: true // 若果设置为true，它则会固定在tags-view中(默认 false)
        }
      },
      {
        path: 'supplierIndex',
        component: () => import('@/views/home/supplierIndex'),
        name: '供应商首页',
        meta: {
          footerHidden: true, // 隐藏底部栏
          title: 'supplierIndex',
          icon: 'dashboard',
          affix: true // 若果设置为true，它则会固定在tags-view中(默认 false)
        }
      }
    ]
  },
  {
    path: '/noticeList',
    name: '公告列表',
    meta: {
      footerHidden: true // 隐藏底部栏
    },
    component: () => import('@/views/home/noticeList')
  },
  {
    path: '/noticeDetail',
    name: '公告详情',
    meta: {
      footerHidden: true // 隐藏底部栏
    },
    component: () => import('@/views/home/noticeDetail')
  },
  {
    path: '/noticeDetailApp',
    name: '公告详情App',
    meta: {
      footerHidden: true // 隐藏底部栏
    },
    component: () => import('@/views/home/noticeDetailApp')
  },
  // 登录页
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  // 忘记密码
  {
    path: '/forget-password',
    component: () => import('@/views/login/ForgetPassword'),
    hidden: true
  },
  // 个人注册
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  },
  // 企业注册
  {
    path: '/EnterpriseRegister',
    component: () => import('@/views/register/EnterpriseRegister'),
    hidden: true
  },
  // 操作手册
  {
    path: '/help-document',
    component: Layout,
    redirect: '/help-document',
    children: [
      {
        path: 'help-document',
        component: () => import('@/views/system/help-document/index.vue'),
        name: 'operation-manual',
        meta: { title: '操作手册', icon: 'el-icon-user-solid', noCache: true }
      }
    ]
  },
  // 个人中心
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile',
    children: [
      {
        path: 'profile',
        component: () => import('@/views/system/profile/index'),
        name: '个人中心',
        meta: { title: '个人中心', icon: 'el-icon-user-solid', noCache: true }
      },
      {
        path: 'enterpriseRecord',
        component: () => import('@/views/system/enterpriseRecord/index'),
        name: '申请记录',
        meta: { title: '申请记录', icon: 'el-icon-user-solid', noCache: true }
      },
      {
        path: 'enterpriseExamin',
        component: () => import('@/views/system/enterpriseExamin'),
        name: '企业列表',
        meta: { title: '企业列表', icon: 'el-icon-user-solid', noCache: true }
      }
    ]
  },
  // 404
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  // 401
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  sysTemRouter, // 系统管理
  enterpriseRouter, // 企业设定
  superviseBaseInfoRouter, // 基本信息
  systemConfig, // 系统配置
  resourceManage, // 资源管理
  PersonalOfficeRouter, // 个人办公
  newProject, // 项目管理
  projectControl, // 项目管控
  statisticalAnalysis // 统计分析
]
const createRouter = () => new Router({
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
